#!/usr/bin/env python
# coding=utf-8

from django.contrib import admin

from .models import Choice, Question, Project

# 客制化管理员界面的表单

#相关的类会直接按照栈的方式进行显示， 比较占垂直空间
class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 3

#相关的类会尽量在一行中显示相关信息， 节约垂直空间，横向扩展较宽
class ChoiceTabularInline(admin.TabularInline):
    model = Choice
    extra = 3

class QuestionAdmin(admin.ModelAdmin):

    # redefine the order appears on the view page
    # fields = ['publish_date', 'content']

    # 控制在索引页面列表中显示的字段, 默认显示对象的__str__ 方法返回结果
    list_display = ('content','publish_date', 'is_published_recently')

    # 在admin管理视图表单中添加过滤器
    list_filter = ['publish_date']

    # 在admin管理视图表单中添加字段搜索
    search_fields = ['content']

    # 控制数据对象信息在admin管理视图表单中的显示布局
    fieldsets = [
        (None, {'fields':['content']}),
        ('Date information', {'fields':['publish_date'], 'classes':['collapse']})
    ]


    inlines =[ChoiceTabularInline]

# Register your models here. 允许admin用户来编辑其他应用的模型
admin.site.register(Question,QuestionAdmin)
admin.site.register(Choice)
admin.site.register(Project)
